# encoding=utf-8_general_ci

import tornado.web
import sae.const
import tornado.database
import os.path
import time

class AdminHandler(tornado.web.RequestHandler):
    def get(self):
        message = ""
        self.render("admin.html", message = message)
    def post(self):
        password = self.get_argument("password", "")
        db =tornado.database.Connection(sae.const.MYSQL_HOST+":"+sae.const.MYSQL_PORT,sae.const.MYSQL_DB, sae.const.MYSQL_USER, sae.const.MYSQL_PASS, 30)

        message = ""

        for each in db.query("SELECT password FROM admin"):
            if each.password == password:
                db.execute("TRUNCATE article")
                db.execute("TRUNCATE comment")
                message = "deleted"
                self.render("admin.html", message = message)

                self.redirect("/")
                return
            
            self.render("admin.html", message = "密码错误")
